n = input()
if int(n) > 999 and int(n) < 10000:
    s1 = n[0]
    s2 = n[1]
    s3 = n[2]
    s4 = n[3]
    a = []
    a.append(int(s1))
    a.append(int(s2))
    a.append(int(s3))
    a.append(int(s4))
    a.append(int(s1+s2))
    a.append(int(s2+s3))
    a.append(int(s3+s4))
    a.append(int(s1+s2+s3))
    a.append(int(s2+s3+s4))
    a.append(int(s1+s2+s3+s4))
    t = 0
    n2 = []
    for c in a:
        t = 0
        for d in range(2, c - 1):
            if c % d == 0:
                t = 1
        if t == 0:
            n2.append(c)
    if len(n2) > 0:
        print(max(n2))
    else:
        print(0)
else:
    print(0)
